package com.liuwei.learning.restful;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.liuwei.learning.jpa.testdb1.Article;
import com.liuwei.learning.model.ArticleVO;
import com.liuwei.learning.service.ArticleRestService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

@Slf4j
@RunWith(SpringRunner.class)
@AutoConfigureWebMvc
@SpringBootTest
public class ArticleRestControllerTest4 {

    @Resource(name = "articleRestJDBCServiceImpl")
    private ArticleRestService articleRestService;

    @Test
    public void saveArticle() throws Exception {
        String article = "{\n" +
                "    \"id\": 1,\n" +
                "    \"author\": \"zimug\",\n" +
                "    \"title\": \"手摸手教你开发spring boot\",\n" +
                "    \"content\": \"c\",\n" +
                "    \"createTime\": \"2017-07-16 05:23:34\",\n" +
                "    \"reader\":[{\"name\":\"zimug\",\"age\":18},{\"name\":\"kobe\",\"age\":37}]\n" +
                "}";
        ObjectMapper objectMapper = new ObjectMapper();
        ArticleVO articleObj = objectMapper.readValue(article, ArticleVO.class);
        articleRestService.saveArticle(articleObj);


    }
}
